import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _selectedIndex = 0;
  final PageController _controller = PageController(initialPage: 0);
  //TextEditingController searchPlanNameController = TextEditingController();
  //FocusNode searchFocusNode = FocusNode();

  final List<Widget> _widgetOptions = <Widget>[
    Container(
      alignment: Alignment.center,
      child: TextField(
        focusNode: FocusNode(),
        controller: TextEditingController(),
        textInputAction: TextInputAction.search,
        cursorColor: Colors.orange,
        textAlignVertical: TextAlignVertical.center,
        cursorHeight: 16,
        style: const TextStyle(fontSize: 16),
        decoration: InputDecoration(
          isDense: true,
          filled: true,
          fillColor: Colors.transparent,
          border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(50),
            borderSide: const BorderSide(
              color: Colors.grey,
              width: 1.0,
            ),
          ),
          enabledBorder: OutlineInputBorder(
            borderRadius: BorderRadius.circular(50),
            borderSide: const BorderSide(
              color: Colors.grey,
              width: 1.0,
            ),
          ),
          focusedBorder: OutlineInputBorder(
            borderRadius: BorderRadius.circular(50),
            borderSide: const BorderSide(
              color: Colors.grey,
              width: 1.0,
            ),
          ),
          contentPadding: EdgeInsets.zero,
          prefixIcon: const Icon(
            Icons.search,
            size: 20,
            color: Colors.grey,
          ),
        ),
      ),
    ),
    Text('首页2'),
    Text('首页3'),
  ];

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  void _onItemTapped(int index) {
    if (index == 1) {
      //Get.toNamed('/addPlan', arguments: null);
    } else {
      _controller.jumpToPage(index);
      setState(() {
        _selectedIndex = index;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      body: PageView(
        physics: NeverScrollableScrollPhysics(),
        controller: _controller,
        children: _widgetOptions,
      ),
      bottomNavigationBar: Container(
        color: Colors.white,
        padding: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            // 左侧导航项
            GestureDetector(
              onTap: () => _onItemTapped(0),
              child: SizedBox(
                height: kBottomNavigationBarHeight,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Icon(
                      Icons.check_circle,
                      color: _selectedIndex == 0 ? Color(0xFFFFA500) : Colors.grey,
                    ),
                    Text(
                      '待办',
                      style: TextStyle(
                        fontSize: 12.0,
                        color: _selectedIndex == 0 ? Color(0xFFFFA500) : Colors.grey,
                      ),
                    ),
                  ],
                ),
              ),
            ),
            // 中间圆形按钮
            GestureDetector(
              onTap: () => _onItemTapped(1),
              child: Container(
                width: 40,
                height: 40,
                margin: EdgeInsets.only(bottom: 2),
                decoration: BoxDecoration(
                  color: Color(0xFFFFA500),
                  shape: BoxShape.circle,
                ),
                child: Icon(
                  Icons.add,
                  color: Colors.white,
                ),
              ),
            ),
            // 右侧导航项
            GestureDetector(
              onTap: () => _onItemTapped(2),
              child: SizedBox(
                height: kBottomNavigationBarHeight,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Icon(
                      Icons.date_range,
                      color: _selectedIndex == 2 ? Color(0xFFFFA500) : Colors.grey,
                    ),
                    Text(
                      '计划',
                      style: TextStyle(
                        fontSize: 12.0,
                        color: _selectedIndex == 2 ? Color(0xFFFFA500) : Colors.grey,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
